package com.zygh.policeasset.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.WitsmallMapper;
import com.zygh.policeasset.pojo.Witsmall;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/WitsmallService.class */
public class WitsmallService {
    @Autowired
    WitsmallMapper witsmallMapper;

    public List<Witsmall> findAll(String type) {
        return this.witsmallMapper.findAll(type);
    }

    public PageInfo listFindByBid(String witbigNum, String type, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.witsmallMapper.findByBnum(witbigNum, type));
    }

    public Witsmall findById(Integer id) {
        return this.witsmallMapper.findById(id);
    }

    public List<Witsmall> findByBid(String witbigNum, String type) {
        List<Witsmall> witsmallList = this.witsmallMapper.findByBnum(witbigNum, type);
        if ("08".equals(witbigNum) && "zn".equals(type)) {
            int i = 0;
            while (i < witsmallList.size()) {
                if ("01".equals(witsmallList.get(i).getWitsmallNum())) {
                    witsmallList.remove(i);
                    i--;
                }
                i++;
            }
        }
        return witsmallList;
    }

    public Integer add(Witsmall params) {
        List<Witsmall> witsmallList = this.witsmallMapper.findByBnum(params.getWitbigNum(), params.getType());
        if (witsmallList.size() != 0) {
            int num = Integer.parseInt(witsmallList.get(witsmallList.size() - 1).getWitsmallNum());
            StringBuffer witsmallNum = new StringBuffer();
            for (int i = 0; i < 2 - String.valueOf(num + 1).length(); i++) {
                witsmallNum.append("0");
            }
            witsmallNum.append(num + 1);
            params.setWitsmallNum(witsmallNum.toString());
        } else {
            params.setWitsmallNum("01");
        }
        return Integer.valueOf(this.witsmallMapper.add(params));
    }

    public Integer update(Witsmall params) {
        return Integer.valueOf(this.witsmallMapper.updateById(params));
    }

    public Integer remove(int id) {
        return Integer.valueOf(this.witsmallMapper.deleteById(Integer.valueOf(id)));
    }

    public String findOneByName(String type, String witbigNum, String unitName) {
        return this.witsmallMapper.findOneByName(type, witbigNum, unitName);
    }

    public Integer findDepreciation(String type, String witbigNum, String witsmallNum) {
        int count = 0;
        try {
            count = this.witsmallMapper.findDepreciation(type, witbigNum, witsmallNum).intValue();
        } catch (Exception e) {
        }
        return Integer.valueOf(count);
    }
}